package com.ts.animal.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.ts.animal.constant.AnimalConstant;
import com.ts.animal.dao.ExportRecordDao;
import com.ts.animal.domain.*;
import com.ts.animal.service.*;
import com.ts.common.constant.CommonConstant;
import com.ts.common.enums.Enums;
import com.ts.common.redis.RedisUtil;
import com.ts.common.utils.*;
import com.ts.system.base.BaseInterface;
import com.ts.system.util.SystemUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;


@Service
public class ExportRecordServiceImpl implements BaseInterface, ExportRecordService {
    private static Logger log = LoggerFactory.getLogger(ExportRecordServiceImpl.class);
    @Autowired
    private ExportRecordDao exportRecordDao;

    @Override
    public ExportRecordDO get(Integer id) {
        return exportRecordDao.get(id);
    }

    @Override
    public List<ExportRecordDO> list(Map<String, Object> map) {
        String testUserNames[] = SystemUtil.getSystemParams().get(AnimalConstant.key_name_test_user_name).getParamValue().split(",");
        if (Lists.newArrayList(testUserNames).contains(ShiroUtils.getUser().getUsername())) {
            map.put(AnimalConstant.test_user_name, AnimalConstant.test_user_name);
            map.put(AnimalConstant.test_user_deptId, ShiroUtils.getUser().getDeptId());
        } else {
            map.putAll(DataPerUitl.deptPer("bs_export_record.dept_id"));
        }
        return exportRecordDao.list(map);
    }

    @Override
    public int count(Map<String, Object> map) {
        return exportRecordDao.count(map);
    }

    @Override
    public int save(Result result, ExportRecordDO exportRecord) {
        int ret = exportRecordDao.save(exportRecord);
        if (ret == 0) {
            result.set(Result.FAIL, "保存失败", null);
        }
        return ret;


    }

    @Override
    public int update(Result result, ExportRecordDO exportRecord) {
        int ret = exportRecordDao.update(exportRecord);
        if (ret == 0) {
            result.set(Result.FAIL, "更新失败", null);
        }
        return ret;
    }

    @Override
    public int remove(Result result, Integer id) {
        int ret = exportRecordDao.remove(id);
        if (ret == 0) {
            result.set(Result.FAIL, "删除失败", null);
        }
        return ret;
    }

    @Override
    public int batchRemove(Result result, Integer[] ids) {
        int ret = exportRecordDao.batchRemove(ids);
        if (ret != ids.length) {
            result.set(Result.FAIL, "部分删除失败", null);
        }
        return ret;
    }

    @Override
    public void init() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    try {
                        long size = RedisUtil.listSize(AnimalConstant.REDIS_BASE_EXPORT_PARAM_DATA_KEY);
                        //从redis中拿到基站发出的数据
                        String dataString = RedisUtil.rpop(AnimalConstant.REDIS_BASE_EXPORT_PARAM_DATA_KEY, String.class);
                        log.info("当前从Redis中取导出数据参数，Redis中数据长度为{},当前取的数据是：{}", size, dataString);
                        JSONObject jsonObject = JSON.parseObject(dataString);
                        //创建文件
                        createFile(jsonObject);
                        if (RedisUtil.listSize(AnimalConstant.REDIS_BASE_EXPORT_PARAM_DATA_KEY) == 0) {
                            log.info("Redis没有导出数据，休眠25秒钟");
                            Thread.sleep(25000l);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        log.info("取导出数据异常，休眠30秒钟");
                        try {
                            Thread.sleep(30000l);
                        } catch (Exception ex) {
                        }
                        log.error("取导出数据异常:{}", e.getMessage());
                    }
                }
            }
        }).start();
    }


    @Override
    public void createFile(JSONObject jsonObject) {
        if (jsonObject == null) {
            return;
        }
        String exportCode = jsonObject.getString(CommonConstant.EXPORT_CODE_FLAG);
        Long exportDept = jsonObject.getLong(CommonConstant.EXPORT_DEPT);
        Long exportUser = jsonObject.getLong(CommonConstant.EXPORT_USER);
        Integer exportId = jsonObject.getInteger(CommonConstant.EXPORT_ID_FLAG);
        //数据权限-根据操作人以及操作人所属部门查询需要导出的数据
        ShiroUtils.setDeptId(exportDept);
        ShiroUtils.setUserId(exportUser);
        //根据业务（exportCode），分发处理
        UtilEasyExcel utilEasyExcel = dispatcherProcess(exportCode, jsonObject);
        if (utilEasyExcel != null) {
            ExportRecordDO exportRecordDO = exportRecordDao.get(exportId);
            exportRecordDO.setExportFinishTime(new Date());
            exportRecordDO.setExportStatus(AnimalConstant.export_finish);
            exportRecordDO.setExportPath(utilEasyExcel.getFilePath());
            exportRecordDao.update(exportRecordDO);
        }
    }

    /**
     * @param exportCode 导出的业务编号
     * @param jsonObject 查询导出数据的条件
     * @return
     */
    private UtilEasyExcel dispatcherProcess(String exportCode, JSONObject jsonObject) {
        UtilEasyExcel utilEasyExcel = null;
        //导出业务类型枚举：Enums.Export   若需要添加新的导出业务，需要增加枚举项
        switch (Enums.Export.getEnum(exportCode)) {
            case bs_access_record:
                AccessRecordService accessRecordService = SpringUtils.getObject(AccessRecordService.class);
                List<AccessRecordDO> accessRecordList = accessRecordService.list(jsonObject);
                //数据格式化处理
                utilEasyExcel = new UtilEasyExcel(jsonObject, accessRecordList, (key, val, obj) -> {
                    if (key.equals("direction")) {
                        return SystemUtil.getDicts().get("access_direction").get(val).getName();
                    }
                    if (key.equals("varietyName")) {
                        return SystemUtil.getDicts().get("animal_varieties").get(val).getName();
                    }
                    if (key.equals("occurrenceTime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    return val;
                });
                //写入文件
                utilEasyExcel.dynamicWrite();
                break;
            case bs_base_station:
                BaseStationService baseStationService = SpringUtils.getObject(BaseStationService.class);
                List<Map<String, Object>> baseStationList = baseStationService.list(jsonObject);
                utilEasyExcel = new UtilEasyExcel(jsonObject, baseStationList, (key, val, obj) -> {
                    if (key.equals("status")) {
                        String status = RedisUtil.get(AnimalConstant.REDIS_BASE_STATION_STATUS_KEY + obj.get("baseStationNum"));
                        if (StringUtils.isNotEmpty(status)) {
                            return SystemUtil.getDicts().get("base_station_status").get(status).getName();
                        }
                        return SystemUtil.getDicts().get("base_station_status").get(val).getName();
                    }
                    if (key.equals("deptId")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getIdDepts().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getIdDepts().get(valLong).getName();
                    }
                    if (key.equals("createTime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    if (key.equals("daG24") || key.equals("daGps") || key.equals("daGsm") || key.equals("daWlan") || key.equals("daLan") || key.equals("daPower") || key.equals("daBattery") || key.equals("daG24")) {
                        return SystemUtil.getDicts().get("baseStation_work_status").get(val).getName();
                    }
                    return val;
                }, true);
                utilEasyExcel.dynamicWrite();
                break;
            case bs_breed_record:
                BreedRecordService breedRecordService = SpringUtils.getObject(BreedRecordService.class);
                List<BreedRecordDO> breedRecordList = breedRecordService.list(jsonObject);
                utilEasyExcel = new UtilEasyExcel(jsonObject, breedRecordList, (key, val, obj) -> {
                    if (key.equals("typeName")) {
                        return SystemUtil.getDicts().get("animal_type").get(val).getName();
                    }
                    if (key.equals("varietyName")) {
                        return SystemUtil.getDicts().get("animal_varieties").get(val).getName();
                    }
                    if (key.equals("deptId")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getIdDepts().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getIdDepts().get(valLong).getName();
                    }
                    if (key.equals("createUser")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getUsers().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getUsers().get(valLong).getName();
                    }
                    if (key.equals("breedTime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    return val;
                });
                utilEasyExcel.dynamicWrite();
                break;
            case bs_customer:
                CustomerService customerService = SpringUtils.getObject(CustomerService.class);
                List<CustomerDO> customerList = customerService.list(jsonObject);
                utilEasyExcel = new UtilEasyExcel(jsonObject, customerList, (key, val, obj) -> {
                    if (key.equals("typeName")) {
                        return SystemUtil.getDicts().get("animal_type").get(val).getName();
                    }
                    if (key.equals("varietyName")) {
                        return SystemUtil.getDicts().get("animal_varieties").get(val).getName();
                    }
                    if (key.equals("deptId")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getIdDepts().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getIdDepts().get(valLong).getName();
                    }
                    if (key.equals("createUser")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getUsers().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getUsers().get(valLong).getName();
                    }
                    return val;
                });
                utilEasyExcel.dynamicWrite();
                break;
            case bs_check_record:
                CheckRecordService checkRecordService = SpringUtils.getObject(CheckRecordService.class);
                List<CheckRecordDO> checkRecordList = checkRecordService.list(jsonObject);
                utilEasyExcel = new UtilEasyExcel(jsonObject, checkRecordList, (key, val, obj) -> {
                    if (key.equals("typeName")) {
                        return SystemUtil.getDicts().get("animal_type").get(val).getName();
                    }
                    if (key.equals("varietyName")) {
                        return SystemUtil.getDicts().get("animal_varieties").get(val).getName();
                    }
                    if (key.equals("deptId")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getIdDepts().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getIdDepts().get(valLong).getName();
                    }
                    if (key.equals("createUser")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getUsers().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getUsers().get(valLong).getName();
                    }
                    return val;
                });
                utilEasyExcel.dynamicWrite();
                break;
            case bs_immune_record:
                ImmuneRecordService immuneRecordService = SpringUtils.getObject(ImmuneRecordService.class);
                List<ImmuneRecordDO> immuneRecordList = immuneRecordService.list(jsonObject);
                utilEasyExcel = new UtilEasyExcel(jsonObject, immuneRecordList, (key, val, obj) -> {
                    if (key.equals("typeName")) {
                        return SystemUtil.getDicts().get("animal_type").get(val).getName();
                    }
                    if (key.equals("varietyName")) {
                        return SystemUtil.getDicts().get("animal_varieties").get(val).getName();
                    }
                    if (key.equals("deptId")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getIdDepts().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getIdDepts().get(valLong).getName();
                    }
                    if (key.equals("createUser")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getUsers().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getUsers().get(valLong).getName();
                    }
                    if (key.equals("createTime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    return val;
                });
                utilEasyExcel.dynamicWrite();
                break;
            case bs_inputs:
                InputsService inputsService = SpringUtils.getObject(InputsService.class);
                List<Map<String, Object>> inputsList = inputsService.exList(jsonObject);
                utilEasyExcel = new UtilEasyExcel(jsonObject, inputsList, (key, val, obj) -> {
                    if (key.equals("typeName")) {
                        return SystemUtil.getDicts().get("animal_type").get(val).getName();
                    }
                    if (key.equals("varietyName")) {
                        return SystemUtil.getDicts().get("animal_varieties").get(val).getName();
                    }
                    if (key.equals("status")) {
                        return SystemUtil.getDicts().get("inputs_status").get(val).getName();
                    }
                    if (key.equals("deptId")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getIdDepts().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getIdDepts().get(valLong).getName();
                    }
                    if (key.equals("createUser")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getUsers().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getUsers().get(valLong).getName();
                    }
                    if (key.equals("createTime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    if (key.equals("birthday")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_PATTERN);
                    }
                    if (key.equals("lastBreedTime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_PATTERN);
                    }
                    return val;
                }, true);
                utilEasyExcel.dynamicWrite();
                break;
            case bs_oestrus_record:
                OestrusRecordService oestrusRecordService = SpringUtils.getObject(OestrusRecordService.class);
                List<OestrusRecordDO> oestrusRecordList = oestrusRecordService.list(jsonObject);
                utilEasyExcel = new UtilEasyExcel(jsonObject, oestrusRecordList, (key, val, obj) -> {
                    if (key.equals("typeName")) {
                        return SystemUtil.getDicts().get("animal_type").get(val).getName();
                    }
                    if (key.equals("varietyName")) {
                        return SystemUtil.getDicts().get("animal_varieties").get(val).getName();
                    }
                    if (key.equals("deptId")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getIdDepts().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getIdDepts().get(valLong).getName();
                    }
                    if (key.equals("createUser")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getUsers().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getUsers().get(valLong).getName();
                    }
                    if (key.equals("oestrusStartTime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    if (key.equals("oestrusEndTime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    return val;
                });
                utilEasyExcel.dynamicWrite();
                break;
            case bs_parturition_record:
                ParturitionRecordService parturitionRecordService = SpringUtils.getObject(ParturitionRecordService.class);
                List<ParturitionRecordDO> parturitionRecordList = parturitionRecordService.list(jsonObject);
                utilEasyExcel = new UtilEasyExcel(jsonObject, parturitionRecordList, (key, val, obj) -> {

                    if (key.equals("typeName")) {
                        return SystemUtil.getDicts().get("animal_type").get(val).getName();
                    }
                    if (key.equals("varietyName")) {
                        return SystemUtil.getDicts().get("animal_varieties").get(val).getName();
                    }
                    if (key.equals("deptId")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getIdDepts().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getIdDepts().get(valLong).getName();
                    }
                    if (key.equals("createUser")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getUsers().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getUsers().get(valLong).getName();
                    }
                    if (key.equals("parturitionTime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    return val;
                });
                utilEasyExcel.dynamicWrite();
                break;
            case bs_rfid_label:
                RfidLabelService rfidLabelService = SpringUtils.getObject(RfidLabelService.class);
                List<RfidLabelDO> rfidLabelList = rfidLabelService.list(jsonObject);
                utilEasyExcel = new UtilEasyExcel(jsonObject, rfidLabelList, (key, val, obj) -> {
                    return val;
                });
                utilEasyExcel.dynamicWrite();
                break;
            case bs_rfid_sync_data:
                RfidSyncDataService rfidSyncDataService = SpringUtils.getObject(RfidSyncDataService.class);
                List<Map<String, Object>> rfidSyncDataList = rfidSyncDataService.list(jsonObject);
                utilEasyExcel = new UtilEasyExcel(jsonObject, rfidSyncDataList, (key, val, obj) -> {
                    if (key.equals("collectionTime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    return val;
                }, true);
                utilEasyExcel.dynamicWrite();
                break;
            case bs_sale_record:
                SaleRecordService saleRecordService = SpringUtils.getObject(SaleRecordService.class);
                List<Map<String, Object>> saleRecordList = saleRecordService.exList(jsonObject);
                utilEasyExcel = new UtilEasyExcel(jsonObject, saleRecordList, (key, val, obj) -> {
                    if (key.equals("typeName")) {
                        return SystemUtil.getDicts().get("animal_type").get(val).getName();
                    }
                    if (key.equals("varietyName")) {
                        return SystemUtil.getDicts().get("animal_varieties").get(val).getName();
                    }
                    if (key.equals("deptId")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getIdDepts().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getIdDepts().get(valLong).getName();
                    }
                    if (key.equals("createUser")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getUsers().get(valLong) == null) {
                            return val;
                        }
                        return SystemUtil.getUsers().get(valLong).getName();
                    }
                    if (key.equals("createTime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    return val;
                }, true);
                utilEasyExcel.dynamicWrite();
                break;
            case bs_sick_record:
                SickRecordService sickRecordService = SpringUtils.getObject(SickRecordService.class);
                List<SickRecordDO> sickRecordList = sickRecordService.list(jsonObject);
                utilEasyExcel = new UtilEasyExcel(jsonObject, sickRecordList, (key, val, obj) -> {

                    if (key.equals("typeName")) {
                        return SystemUtil.getDicts().get("animal_type").get(val).getName();
                    }
                    if (key.equals("varietyName")) {
                        return SystemUtil.getDicts().get("animal_varieties").get(val).getName();
                    }
                    if (key.equals("deptId")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getIdDepts().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getIdDepts().get(valLong).getName();
                    }
                    if (key.equals("createUser")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getUsers().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getUsers().get(valLong).getName();
                    }
                    if (key.equals("sickTime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    if (key.equals("createTime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    return val;
                });
                utilEasyExcel.dynamicWrite();
                break;
            case bs_space:
                SpaceService spaceService = SpringUtils.getObject(SpaceService.class);
                List<SpaceDO> spaceList = spaceService.list(jsonObject);
                utilEasyExcel = new UtilEasyExcel(jsonObject, spaceList, (key, val, obj) -> {
                    if (key.equals("typeName")) {
                        return SystemUtil.getDicts().get("animal_type").get(val).getName();
                    }
                    if (key.equals("varietyName")) {
                        return SystemUtil.getDicts().get("animal_varieties").get(val).getName();
                    }
                    if (key.equals("deptId")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getIdDepts().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getIdDepts().get(valLong).getName();
                    }
                    if (key.equals("createUser")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getUsers().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getUsers().get(valLong).getName();
                    }
                    return val;
                });
                utilEasyExcel.dynamicWrite();
                break;
            case bs_substandard_data:
                SubstandardDataService substandardDataService = SpringUtils.getObject(SubstandardDataService.class);
                List<SubstandardDataDO> substandardDataList = substandardDataService.list(jsonObject);
                utilEasyExcel = new UtilEasyExcel(jsonObject, substandardDataList, (key, val, obj) -> {
                    if (key.equals("typeName")) {
                        return SystemUtil.getDicts().get("animal_type").get(val).getName();
                    }
                    if (key.equals("varietyName")) {
                        return SystemUtil.getDicts().get("animal_varieties").get(val).getName();
                    }
                    if (key.equals("substandardReason")) {
                        return SystemUtil.getDicts().get("substandard_reason").get(val).getName();
                    }
                    if (key.equals("deptId")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getIdDepts().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getIdDepts().get(valLong).getName();
                    }
                    if (key.equals("createUser")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getUsers().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getUsers().get(valLong).getName();
                    }
                    if (key.equals("approvalId")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getUsers().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getUsers().get(valLong).getName();
                    }
                    if (key.equals("createTime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    if (key.equals("approvalTime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    return val;
                });
                utilEasyExcel.dynamicWrite();
                break;
            case bs_supplier:
                SupplierService supplierService = SpringUtils.getObject(SupplierService.class);
                List<SupplierDO> supplierList = supplierService.list(jsonObject);
                utilEasyExcel = new UtilEasyExcel(jsonObject, supplierList, (key, val, obj) -> {
                    if (key.equals("typeName")) {
                        return SystemUtil.getDicts().get("animal_type").get(val).getName();
                    }
                    if (key.equals("varietyName")) {
                        return SystemUtil.getDicts().get("animal_varieties").get(val).getName();
                    }
                    if (key.equals("deptId")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getIdDepts().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getIdDepts().get(valLong).getName();
                    }
                    if (key.equals("createUser")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getUsers().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getUsers().get(valLong).getName();
                    }
                    return val;
                });
                utilEasyExcel.dynamicWrite();
                break;
            case bs_warning_record:
                WarningRecordService warningRecordService = SpringUtils.getObject(WarningRecordService.class);
                List<Map<String, Object>> warningRecordList = warningRecordService.list(jsonObject);
                utilEasyExcel = new UtilEasyExcel(jsonObject, warningRecordList, (key, val, obj) -> {
                    if (key.equals("typeName")) {
                        return SystemUtil.getDicts().get("animal_type").get(val).getName();
                    }
                    if (key.equals("varietyName")) {
                        return SystemUtil.getDicts().get("animal_varieties").get(val).getName();
                    }
                    if (key.equals("deptId")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getIdDepts().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getIdDepts().get(valLong).getName();
                    }
                    if (key.equals("warningType")) {
                        return SystemUtil.getDicts().get("warning_type").get(val).getName();
                    }
                    if (key.equals("warningTime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    return val;
                }, true);
                utilEasyExcel.dynamicWrite();
                break;
            case bs_rfid_label_import:
                RfidLabelImportService rfidLabelImportService = SpringUtils.getObject(RfidLabelImportService.class);
                List<Map<String, Object>> rfidLabelImport = rfidLabelImportService.list(jsonObject);
                utilEasyExcel = new UtilEasyExcel(jsonObject, rfidLabelImport, (key, val, obj) -> {
                    if (key.equals("importDatetime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    return val;
                }, true);
                utilEasyExcel.dynamicWrite();
                break;
            case bs_rfid_label_use_info:
                RfidLabelUseInfoService rfidLabelUseInfoService = SpringUtils.getObject(RfidLabelUseInfoService.class);
                List<Map<String, Object>> rfidLabelUseInfo = rfidLabelUseInfoService.list(jsonObject);
                utilEasyExcel = new UtilEasyExcel(jsonObject, rfidLabelUseInfo, (key, val, obj) -> {
                    if (key.equals("useStatus")) {
                        return SystemUtil.getDicts().get("use_status").get(val).getName();
                    }
                    if (key.equals("settlementId")) {
                        return SystemUtil.getDicts().get("settlement_status").get(AnimalConstant.settlement_status_yes).getName();
                    }
                    if (key.equals("deptId")) {
                        Long valLong = Long.valueOf(val.toString());
                        if (SystemUtil.getIdDepts().get(valLong) == null) {
                            return "";
                        }
                        return SystemUtil.getIdDepts().get(valLong).getName();
                    }
                    if (key.equals("firstUseDatetime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    if (key.equals("importDatetime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    if (key.equals("settlementDatetime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    return val;
                }, true);
                utilEasyExcel.dynamicWrite();
                break;
            case bs_rfid_label_settlement:
                RfidLabelSettlementService rfidLabelSettlementService = SpringUtils.getObject(RfidLabelSettlementService.class);
                List<Map<String, Object>> rfidLabelSettlementList = rfidLabelSettlementService.list(jsonObject);
                utilEasyExcel = new UtilEasyExcel(jsonObject, rfidLabelSettlementList, (key, val, obj) -> {
                    if (key.equals("verifyStatus")) {
                        return SystemUtil.getDicts().get("verify_status").get(val).getName();
                    }
                    if (key.equals("verifyDatetime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    if (key.equals("settlementDatetime")) {
                        return DateUtils.stampToDate(val.toString(), DateUtils.DATE_TIME_PATTERN);
                    }
                    return val;
                }, true);
                utilEasyExcel.dynamicWrite();
                break;
            default:
                break;
        }
        return utilEasyExcel;
    }
}
